/*
$(document).ready(function () {
    $("#sub").click(function () {
        //英文
        var pattern = new RegExp("[a-zA-Z]+");
        //数字
        var pattern2 = new RegExp("[0-9]+");
        //中文
        var pattern3 = new RegExp("[\u4E00-\u9FA5]+");
        //姓名长度限制
        var pattern6 = new RegExp("/^[\u4E00-\u9FA5]{2,4}$/");
        //特殊字符
        var pattern5 = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
        //身份证号
        var pattern6 = new RegExp("^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$");
        if ($("#username").val() == "") {
            alert("姓名不能为空！😊");
            return false;
        }

        if ($("#tel").val() == "") {
            alert("手机号不能为空！");
            return false;
        }

        if ($("#UID").val() == "") {
            alert("身份证不能为空");
            return false;
        }

        if (pattern.test($("#username").val())
            || pattern2.test($("#username").val())
            || pattern5.test($("#username").val())) {
            alert("请输入正确的名字！");
            return false;
        }

        if (!(/^[\u4E00-\u9FA5]{2,4}$/.test($("#username").val()))) {
            alert("姓名只能在2-4位！");
            return false;
        }

        if (pattern3.test($("#tel").val())
            || pattern.test($("#tel").val())
            || pattern5.test($("#tel").val())) {
            alert("请输入正确的手机号");
            return false;
        }

        if (!(/^1[3456789]\d{9}$/.test($("#tel").val()))) {
            alert("请输入正确的手机号");
            return false;
        }

        if (pattern3.test($("#UID").val())
            || pattern.test($("#UID").val())
            || pattern5.test($("#UID").val())) {
            alert("请输入正确的身份证号！");
            return false;
        }

        if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test($("#UID").val()))) {
            alert("请输入正确的身份证号！");
            return false;
        }
    })
});

function login3() {
    var name = $("#username").val();
    var tel = $("#tel").val();
    var uid = $("#UID").val();
    $.ajax({
        url: "addUser.action",
        type: "post",
        async: true,
        dataType: "json",
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: {
            "user1.name": name,
            "user1.tel": tel,
            "user1.UID": uid
        },
        success: function (data) {
        },
        error: function () {
            alert("添加客户,请求失败！");
        }
    })
}*/
function submits() {

    var voer = $("#verCode").val();
    if (voer != code) {
        alert("验证码输入有误！");
        return;
    }

    //英文
    var pattern = new RegExp("[a-zA-Z]+");
    //数字
    var pattern2 = new RegExp("[0-9]+");
    //中文
    var pattern3 = new RegExp("[\u4E00-\u9FA5]+");
    //姓名长度限制
    var pattern6 = new RegExp("/^[\u4E00-\u9FA5]{2,4}$/");
    //特殊字符
    var pattern5 = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
    //身份证号
    var pattern6 = new RegExp("^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$");

    if ($("#viewImg").attr("src") == "") {
        alert("头像还没选！");
        return false;
    }

    if ($("#viewImg1").attr("src") == "") {
        alert("身份证正面照不能为空！");
        return false;
    }

    if ($("#viewImg2").attr("src") == "") {
        alert("身份证反面照不能为空！");
        return false;
    }
    var b = $("#agree").prop("checked");
    if (!b) {
        alert("协议还没同意！");
        return false;
    }

    if ($("#verCode").val() == "") {
        alert("验证码不能为空！")
        return false;
    }

    if ($("#username").val() == "") {
        alert("姓名不能为空！");
        return false;
    }

    if ($("#tel").val() == "") {
        alert("手机号不能为空！");
        return false;
    }

    if ($("#UID").val() == "") {
        alert("身份证不能为空！");
        return false;
    }

    if (pattern.test($("#username").val())
        || pattern2.test($("#username").val())
        || pattern5.test($("#username").val())) {
        alert("请输入正确的名字！");
        return false;
    }

    if (!(/^[\u4E00-\u9FA5]{2,4}$/.test($("#username").val()))) {
        alert("姓名只能在2-4位！");
        return false;
    }

    if (pattern3.test($("#tel").val())
        || pattern.test($("#tel").val())
        || pattern5.test($("#tel").val())) {
        alert("请输入正确的手机号");
        return false;
    }

    if (!(/^1[3456789]\d{9}$/.test($("#tel").val()))) {
        alert("请输入正确的手机号");
        return false;
    }

    if (pattern3.test($("#UID").val())
        || pattern.test($("#UID").val())
        || pattern5.test($("#UID").val())) {
        alert("请输入正确的身份证号！");
        return false;
    }

    if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test($("#UID").val()))) {
        alert("请输入正确的身份证号！");
        return false;
    }


    var username = $("#username").val();
    var tel = $("#tel").val();
    var Uid = $("#UID").val();
    document.cookie = "username=" + username;
    $.ajax({
        url: "addUser.action",
        type: "post",
        async: true,
        dataType: "json",// 表示请求的返回数据格式:{"username":"sss","password":"1234"}
        // 类型和字符集
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        // 传参
        data: {
            "applicationEntity.customename": username,
            "applicationEntity.customephone": tel,
            "applicationEntity.customeuid": Uid
        },
        success: function (data) {// 回调函数
            // data是否保存成功

            alert(data);
            if (data.add == "用户不存在！") {
                window.location.href = "survey.jsp";
            } else {
                alert("提交失败")
                return false;
            }

        }, error: function () {
            alert("添加客户失败！");
        }
    });
}

function getCode() {
    curCount = count;
    var customerTel = $("#customerTel").val();
    var customerTelError = $("#customerTelError").text();

    if (customerTel != "") {
        if (customerTelError == "") {
            // 产生验证码
            for (var i = 0; i < codeLength; i++) {
                code += parseInt(Math.random() * 9).toString();
            }
            console.log(code);
            // 设置button效果，開始计时
            sendMessage();

        }
    } else {
        document.getElementById("sendMessage").innerHTML = " X 手机号码为空";
    }
}

function sendMessage() {
    var customerTel = $("#tel").val();
    console.log(customerTel + "," + code);

    // 向后台发送处理数据
    $.ajax({
        url: "sendMsg.action",
        type: "post",
        async: true,
        dataType: "json",
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: {
            "tel": customerTel,
            "code": code
        },
        success: function (data) {
            data = parseInt(data.infocode);
            if (data == 1) {
                $("#customerTelError").html("√ 短信验证码已发到您的手机,请查收");
                $("#sendMessage").attr("disabled", "true");
                $("#sendMessage").val("请在" + curCount + "秒内输入验证码");
                InterValObj = window.setInterval(SetRemainTime, 1000); // 启动计时器。1秒运行一次

            } else if (data == 0) {
                $("#customerTelError").html("× 短信验证码发送失败，请再一次发送");
            }
        }
    });
}

//短信验证码
var InterValObj; //timer变量，控制时间
var count = 60; //间隔函数，1秒运行
var curCount;//当前剩余秒数
var code = ""; //验证码
var codeLength = 4;//验证码长度

function SetRemainTime() {
    if (curCount == 0) {
        window.clearInterval(InterValObj);// 停止计时器
        $("#sendMessage").removeAttr("disabled");// 启用按钮
        $("#sendMessage").val("一次发送验证码");
        code = ""; // 清除验证码。假设不清除。过时间后，输入收到的验证码依旧有效
    } else {
        curCount--;
        $("#sendMessage").html("请在" + curCount + "秒内输入验证码");
    }
}

$(document).ready(function () {

})


//设置cookie
var setCookie = function (name, value, day) {
    //当设置的时间等于0时，不设置expires属性，cookie在浏览器关闭后删除
    var expires = day * 24 * 60 * 60 * 1000;
    var exp = new Date();
    exp.setTime(exp.getTime() + expires);
    document.cookie = name + "=" + value + ";expires=" + exp.toUTCString();


};
//删除cookie
var delCookie = function (name) {
    setCookie(name, ' ', -1);
};


function aaa() {
    var name = $("#username").val();
    var uid = $("#UID").val();

    setCookie('name', name, 7);
    setCookie('uid', uid, 7);
}